import { graph } from "@/views/business/mapManagement/components/mapNode";
import { edgeAttrs, edgeRouter } from "@/utils/antvx6/configurationDetails";
/**
 * 修改节点详情
 * @param { object }  nodeData 节点详情
 */
const updateNodes = async (nodeData: any): Promise<any> => {
  if (!["node-point"].includes(nodeData.shape)) Promise.resolve();
  const getCell = graph.value.getCellById(nodeData.nodeNameEn);
  if (!getCell || !getCell.isNode()) return Promise.resolve();
  const param = {
    angle: nodeData.angle,
    hasDirection: nodeData.hasDirection,
    mapNodeType: nodeData.mapNodeType,
    nodeNameCn: nodeData.nodeNameCn,
    nodeNameEn: nodeData.nodeNameEn,
    x: nodeData.x,
    y: nodeData.y,
  };
  getCell.prop("angleDirection", nodeData.angle);
  return getCell.updateData(param);
};

/**
 * 修改边详情
 * @param { object }  edgeData 边详情
 */
const updateEdges = async (edgeData: any): Promise<any> => {
  if (!["edge"].includes(edgeData.shape)) return Promise.resolve();
  const getEdgeCell = graph.value.getCellById(edgeData.edgeName);
  if (!getEdgeCell || !getEdgeCell.isEdge()) return Promise.resolve();
  const param = {
    edgeType: edgeData.edgeType,
    lineMode: edgeData.lineMode,
    lengths: edgeData.lengths,
    edgeName: edgeData.edgeName,
    startNodeId: edgeData.startNodeId,
    endNodeId: edgeData.endNodeId,
  };
  getEdgeCell.updateAttrs(edgeAttrs(2, param.lineMode));
  getEdgeCell.setRouter(edgeRouter(param.edgeType));
  return getEdgeCell.updateData(param);
};

/**
 * 修改区域详情
 * @param { object }  areaData 区域详情
 */
const updateArea = async (areaData: any):Promise<any> => {
  console.log(areaData, "修改区域详情");
  if (!["node-area"].includes(areaData.shape)) Promise.resolve();
  const getCell = graph.value.getCellById(areaData.zoneNameEn);
  if (!getCell || !getCell.isNode()) return Promise.resolve();
  const param = {
    zoneNameEn: areaData.zoneNameEn,
    zoneName: areaData.zoneName,
    tempSize: areaData.tempSize,
    points: areaData.points,
    x: areaData.x,
    y: areaData.y,
    zoneFunction: areaData.zoneFunction
  }
  return getCell.updateData(param);
}

export { updateNodes, updateEdges, updateArea };
